function Tree(obj) {
	UiElement.call(this, obj, "ul");
	return this;
}

function TreeItem(obj) {
	var img = createItemImg(obj);
	var ico = createItemImg(obj);
	var pEle = eles[obj.parentId];

	ico.src = "img/tree/page.gif";
	img.src = "img/tree/join.gif";

	UiElement.call(this, obj, "li");

	this.attribute = function(name, value) {
		if (name == "isLast") {
			if (value) {
				this.items[0].src = "img/tree/joinbottom.gif";
				this.isLast = true;
				if (eles[this.parent].srcObj.type == "TreeItem") {
					if (eles[this.parent].isLast) {
						eles[this.parent].ul.style['background'] = '';
					}
					expandTreeItem(eles[this.parent]);
				}
			}
		} else {
			this.uiEle.setAttribute(name, value);
		}
	};

	var div = createElement('div');
	div.innerText = obj.title;
	obj.expand = false;
	if (eles[obj.parentId].srcObj.type == "TreeItem") {
		if (eles[obj.parentId].ul) {

		} else {
			addEvent(eles[obj.parentId].items[0], "click", function() {
				if (eles[obj.parentId].srcObj.type == "TreeItem") {
					expandTreeItem(eles[obj.parentId]);
				}
			});
			eles[obj.parentId].ul = createItemUl(obj);

			addEles(obj.parentId, [ eles[obj.parentId].ul ]);
		}
		addEles(eles[obj.parentId].ul.id, [ this.uiEle ]);
	}
	addEles(obj.id, [ img, ico, div ]);
	this.items = [ img, ico, div ];

	return this;
}
function createItemUl(obj) {
	var ul = createElement('ul');
	ul.id = obj.parentId + "ul";
	ul.setAttribute("class", "itemUl");
	ul.style['background'] = 'url(./img/tree/line.gif) 0 0 repeat-y';
	return ul;
}
function createItemImg(obj) {
	var img = createElement('img');
	img.setAttribute("class", "itemImg");
	return img;
}
function expandTreeItem(obj) {
	if (obj.expand) {
		if (obj.isLast) {
			obj.items[0].src = "img/tree/minusbottom.gif";
		} else {
			obj.items[0].src = "img/tree/minus.gif";
		}
		obj.items[1].src = "img/tree/folderopen.gif";
		if (obj.ul) {
			obj.ul.style["display"] = "block";
		}
	} else {
		if (obj.isLast) {
			obj.items[0].src = "img/tree/plusbottom.gif";
		} else {
			obj.items[0].src = "img/tree/plus.gif";
		}
		obj.items[1].src = "img/tree/folder.gif";
		if (obj.ul) {
			obj.ul.style["display"] = "none";
		}
	}
	obj.expand = !obj.expand;
}
